// src.helper.dataformat.helper

var moment = require('moment');
moment.locale('zh-cn');

exports.fromatDate = function (context, options) {
  if (!options && context.hasOwnProperty('hash')) {
    options = context;
    context = undefined;

    if (this.published_at) context = this.published_at;
  }
  context = context === null ? undefined : context;

  var format = options.hash.format || 'YYYY年MM月DD日';
  var timeago = options.hash.timeago;
  var date;

  if (timeago) {
    date = moment(context).fromNow();
  } else {
    date = moment(context).format(format);
  }

  return date;
};

exports.getCurrentTime = function (){
  var d,s;
  d = new Date();
  s = d.getFullYear() + "-";             //取年份
  s = s + (d.getMonth() + 1) + "-";      //取月份
  s += d.getDate() + " ";                //取日期
  s += d.getHours() + ":";               //取小时
  s += d.getMinutes() + ":";             //取分
  s += d.getSeconds();                   //取秒
  return(s);
};

exports.getCurrentDate = function(){
  var second = new Date().getTime();
  return [parseInt(second/60/60%24), parseInt(second/60%60), second%60].join(":").replace(/\b(\d)\b/g, "0$1");
};